using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQVW_ABFOLGE
    {
        public DataRow Convert2QVW_ABFOLGE(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQVW_ABFOLGE(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["KAUF"] = " ".PadRight(9 ); 
         dwReturn["AUFTYP"] = " ".PadRight(1 ); 
         dwReturn["PKRS"] = " ".PadRight(2 ); 
         dwReturn["PLFD"] = " ".PadRight(6 ); 
         dwReturn["PPOS"] = " ".PadRight(3 ); 
         dwReturn["PAUF"] = " ".PadRight(12 ); 
         dwReturn["PFSTEP"] = " ".PadRight(3 ); 
         dwReturn["ABFSTATUS"] = " ".PadRight(1 ); 
         dwReturn["ABFKSTKRS"] = " ".PadRight(2 ); 
         dwReturn["ABFKST"] = " ".PadRight(4 ); 
         dwReturn["KST"] = " ".PadRight(6 ); 
         dwReturn["KOPERATION"] = " ".PadRight(15 ); 
         dwReturn["KOPEBEZ"] = " ".PadRight(10 ); 
         dwReturn["MTYPE"] = " ".PadRight(8 ); 
         dwReturn["ABFPLANKZ"] = " ".PadRight(1 ); 
         dwReturn["LSNR"] = " ".PadRight(8 ); 
         dwReturn["MACHINE"] = " ".PadRight(8 ); 
         dwReturn["ABFSOLLSTK"] = " ".PadRight(0 ); 
         dwReturn["PLANKG"] = " ".PadRight(0 ); 
         dwReturn["ABFSOLLME"] = " ".PadRight(1 ); 
         dwReturn["PLANMTR"] = " ".PadRight(0 ); 
         dwReturn["AKG"] = " ".PadRight(0 ); 
         dwReturn["AMTR"] = " ".PadRight(0 ); 
         dwReturn["ABFFIX"] = " ".PadRight(1 ); 
         dwReturn["PFSTART"] = " ".PadRight(0 ); 
         dwReturn["PFEND"] = " ".PadRight(0 ); 
         dwReturn["AFDSTART"] = " ".PadRight(0 ); 
         dwReturn["AFTSTART"] = " ".PadRight(0 ); 
         dwReturn["AFDEND"] = " ".PadRight(0 ); 
         dwReturn["AFTEND"] = " ".PadRight(0 ); 
         dwReturn["RPAUF"] = " ".PadRight(12 ); 
         dwReturn["LO"] = " ".PadRight(2 ); 
         dwReturn["LB"] = " ".PadRight(2 ); 
         dwReturn["FCOST"] = " ".PadRight(0 ); 
         dwReturn["MCOST"] = " ".PadRight(0 ); 
         dwReturn["MBOMCOST"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQVW_ABFOLGE(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQVW_ABFOLGE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQVW_ABFOLGE(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQVW_ABFOLGE(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQVW_ABFOLGE(dwLocal, ITXDBVERSION);
            }
            UpdateQVW_ABFOLGE(dwLocal);
        }
        public void InsertQVW_ABFOLGE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QVW_ABFOLGE(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQVW_ABFOLGE(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QVW_ABFOLGE WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QVW_ABFOLGE  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QVW_ABFOLGE";
            Return = Result;
            return Return;
        }
        public void DeleteQVW_ABFOLGE(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QVW_ABFOLGE   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQVW_ABFOLGE(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QVW_ABFOLGE SET "
                    +"KAUF= :KAUF,"
                    +"AUFTYP= :AUFTYP,"
                    +"PKRS= :PKRS,"
                    +"PLFD= :PLFD,"
                    +"PPOS= :PPOS,"
                    +"PAUF= :PAUF,"
                    +"PFSTEP= :PFSTEP,"
                    +"ABFSTATUS= :ABFSTATUS,"
                    +"ABFKSTKRS= :ABFKSTKRS,"
                    +"ABFKST= :ABFKST,"
                    +"KST= :KST,"
                    +"KOPERATION= :KOPERATION,"
                    +"KOPEBEZ= :KOPEBEZ,"
                    +"MTYPE= :MTYPE,"
                    +"ABFPLANKZ= :ABFPLANKZ,"
                    +"LSNR= :LSNR,"
                    +"MACHINE= :MACHINE,"
                    +"ABFSOLLSTK= :ABFSOLLSTK,"
                    +"PLANKG= :PLANKG,"
                    +"ABFSOLLME= :ABFSOLLME,"
                    +"PLANMTR= :PLANMTR,"
                    +"AKG= :AKG,"
                    +"AMTR= :AMTR,"
                    +"ABFFIX= :ABFFIX,"
                    +"PFSTART= :PFSTART,"
                    +"PFEND= :PFEND,"
                    +"AFDSTART= :AFDSTART,"
                    +"AFTSTART= :AFTSTART,"
                    +"AFDEND= :AFDEND,"
                    +"AFTEND= :AFTEND,"
                    +"RPAUF= :RPAUF,"
                    +"LO= :LO,"
                    +"LB= :LB,"
                    +"FCOST= :FCOST,"
                    +"MCOST= :MCOST,"
                    +"MBOMCOST= :MBOMCOST,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("KAUF", OracleType.NVarChar).Value = dwData["KAUF"].ToString(); 
          or1.Parameters.Add("AUFTYP", OracleType.NVarChar).Value = dwData["AUFTYP"].ToString(); 
          or1.Parameters.Add("PKRS", OracleType.NVarChar).Value = dwData["PKRS"].ToString(); 
          or1.Parameters.Add("PLFD", OracleType.NVarChar).Value = dwData["PLFD"].ToString(); 
          or1.Parameters.Add("PPOS", OracleType.NVarChar).Value = dwData["PPOS"].ToString(); 
          or1.Parameters.Add("PAUF", OracleType.NVarChar).Value = dwData["PAUF"].ToString(); 
          or1.Parameters.Add("PFSTEP", OracleType.NVarChar).Value = dwData["PFSTEP"].ToString(); 
          or1.Parameters.Add("ABFSTATUS", OracleType.NVarChar).Value = dwData["ABFSTATUS"].ToString(); 
          or1.Parameters.Add("ABFKSTKRS", OracleType.NVarChar).Value = dwData["ABFKSTKRS"].ToString(); 
          or1.Parameters.Add("ABFKST", OracleType.NVarChar).Value = dwData["ABFKST"].ToString(); 
          or1.Parameters.Add("KST", OracleType.NVarChar).Value = dwData["KST"].ToString(); 
          or1.Parameters.Add("KOPERATION", OracleType.NVarChar).Value = dwData["KOPERATION"].ToString(); 
          or1.Parameters.Add("KOPEBEZ", OracleType.NVarChar).Value = dwData["KOPEBEZ"].ToString(); 
          or1.Parameters.Add("MTYPE", OracleType.NVarChar).Value = dwData["MTYPE"].ToString(); 
          or1.Parameters.Add("ABFPLANKZ", OracleType.NVarChar).Value = dwData["ABFPLANKZ"].ToString(); 
          or1.Parameters.Add("LSNR", OracleType.NVarChar).Value = dwData["LSNR"].ToString(); 
          or1.Parameters.Add("MACHINE", OracleType.NVarChar).Value = dwData["MACHINE"].ToString(); 
          or1.Parameters.Add("ABFSOLLSTK", OracleType.NVarChar).Value = dwData["ABFSOLLSTK"].ToString(); 
          or1.Parameters.Add("PLANKG", OracleType.NVarChar).Value = dwData["PLANKG"].ToString(); 
          or1.Parameters.Add("ABFSOLLME", OracleType.NVarChar).Value = dwData["ABFSOLLME"].ToString(); 
          or1.Parameters.Add("PLANMTR", OracleType.NVarChar).Value = dwData["PLANMTR"].ToString(); 
          or1.Parameters.Add("AKG", OracleType.NVarChar).Value = dwData["AKG"].ToString(); 
          or1.Parameters.Add("AMTR", OracleType.NVarChar).Value = dwData["AMTR"].ToString(); 
          or1.Parameters.Add("ABFFIX", OracleType.NVarChar).Value = dwData["ABFFIX"].ToString(); 
          or1.Parameters.Add("PFSTART", OracleType.NVarChar).Value = dwData["PFSTART"].ToString(); 
          or1.Parameters.Add("PFEND", OracleType.NVarChar).Value = dwData["PFEND"].ToString(); 
          or1.Parameters.Add("AFDSTART", OracleType.NVarChar).Value = dwData["AFDSTART"].ToString(); 
          or1.Parameters.Add("AFTSTART", OracleType.NVarChar).Value = dwData["AFTSTART"].ToString(); 
          or1.Parameters.Add("AFDEND", OracleType.NVarChar).Value = dwData["AFDEND"].ToString(); 
          or1.Parameters.Add("AFTEND", OracleType.NVarChar).Value = dwData["AFTEND"].ToString(); 
          or1.Parameters.Add("RPAUF", OracleType.NVarChar).Value = dwData["RPAUF"].ToString(); 
          or1.Parameters.Add("LO", OracleType.NVarChar).Value = dwData["LO"].ToString(); 
          or1.Parameters.Add("LB", OracleType.NVarChar).Value = dwData["LB"].ToString(); 
          or1.Parameters.Add("FCOST", OracleType.NVarChar).Value = dwData["FCOST"].ToString(); 
          or1.Parameters.Add("MCOST", OracleType.NVarChar).Value = dwData["MCOST"].ToString(); 
          or1.Parameters.Add("MBOMCOST", OracleType.NVarChar).Value = dwData["MBOMCOST"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
